﻿@using QH.JobBack.Model;
@{

    var modulist = ViewBag.moduleList as List<Module>;

    var parentMenu = ViewBag.parentMenu as List<MenuInfo>;

    var menu =  Model as MenuInfo;
}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>修改菜单 - QAdmin后台模板</title>
    <link rel="stylesheet" href="~/static/common/layui/css/layui.css">
    <link rel="stylesheet" href="~/static/admin/css/style.css">
    <script src="~/static/common/layui/layui.js"></script>
    <script src="~/static/common/jquery-3.3.1.min.js"></script>
    <script src="~/static/common/vue.min.js"></script>
</head>
<body>
    <div id="app">
        

        <div class="main" id="app">
            
            <!--右侧-->
            <div class="">
                <fieldset class="layui-elem-field layui-field-title">
                    <legend>修改菜单</legend>
                </fieldset>
                <form class="layui-form " action="/Menu/Add" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属组</label>
                        <div class="layui-input-inline">
                            <select name="ModuleId" lay-filter="demo" lay-verify="required">
                                @foreach (var item in modulist)
                                {
                                    if (@item.Id == @menu.ModuleId)
                                    {
                                        <option value=@item.Id selected>@item.Name</option>
                                    }
                                    else
                                    {
                                        <option value=@item.Id>@item.Name</option>
                                    }
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">上级菜单</label>
                        <div class="layui-input-inline">
                            <select name="ParentId" id="caiDan" lay-verify="required">
                                @foreach (var item in parentMenu)
                                {
                                    if (@item.MenuId == @menu.ParentId)
                                    {
                                        <option value=@item.MenuId selected>@item.MenuName</option>
                                    }
                                    else
                                    {
                                        <option value=@item.MenuId>@item.MenuName</option>
                                    }
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">菜单名称</label>
                        <div class="layui-input-block">
                            <input type="hidden" value="@menu.MenuId" name="MenuId" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                            <input type="text" value="@menu.MenuName" name="MenuName" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">菜单地址</label>
                        <div class="layui-input-block">
                            <input type="text" value="@menu.Url" name="Url" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">菜单图标</label>
                        <div class="layui-input-block">
                            <input type="text" value="@menu.Ico" name="Ico" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">是否显示</label>
                        <div class="layui-input-block">
                            <input type="checkbox" value="@menu.Status" id="Status" name="Status" lay-text="开启|关闭" checked="" lay-skin="switch" lay-filter="swtichShow">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="submit">立即提交</button>
                        </div>
                    </div>
                </form>

            </div>
        </div>
    </div>
    <script src="~/static/admin/js/script.js"></script>
    <script>
        $(function () {
            if ($("#Status").val()=='value') {
                $("#Status").attr('checked', 'checked');
            } else {
                $("#Status").removeAttr('checked');
            }
            layui.use('form', function () {
                var form = layui.form,
                    layer = layui.layer,
                    $ = layui.jquery;
                 //监听是否显示开关
                form.on('switch(swtichShow)', function (data) {
                    var _this = $(this);
                    if (this.checked) {
                        _this.val(true)
                    }
                    else {
                        _this.val(false)
                    }
                });
                //表单提交
                form.on('submit(submit)', function (data) {
                    $.ajax({
                        type: "Post",
                        url: '/Menu/UpdMenu',
                        data: data.field,
                        async: false,
                        success: function (data) {
                            if (data.success) {
                                layer.msg(data.msg, {
                                    title: '提示框',
                                    icon: 1,
                                    time: 400
                                }, function () {
                                    window.location.href = '/Menu/Index';
                                });
                            } else {
                                layer.alert(data.msg);
                            }
                        }
                    });
                    return false;
                });
            });
        });




    </script>
</body>
</html>

